/**
 * InteractiveObject
 * Defines a DisplayObject3D as a clickable object and applies
 * a cursor change on rollover.
 *
 * @author		Craig Phares
 * @version		2.0
 */
package com.rad.papervision3d {
	
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.view.Viewport3D;
	
	public class InteractiveObject {
		
		private var _viewport:Viewport3D;	// the viewport where the object resides
		
		/**
		 * Specifies an object as clickable and applies mouse events to its viewport.
		 *
		 * @param object		the DisplayObject3D to define as clickable
		 * @param viewport		the viewport where the object resides
		 */
		public function InteractiveObject(object:DisplayObject3D, viewport:Viewport3D) {
			_viewport = viewport;
			object.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onObjectOver);
			object.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onObjectOut);
		}
		
		/**
		 * event triggered on mouse over
		 * sets the cursor to pointer
		 *
		 * @param e		mouse event
		 */
		private function onObjectOver(e:InteractiveScene3DEvent):void {
			_viewport.buttonMode = true;
		}
		/**
		 * event triggered on mouse out
		 * sets the cursor to arrow
		 *
		 * @param e		mouse event
		 */
		private function onObjectOut(e:InteractiveScene3DEvent):void {
			_viewport.buttonMode = false;
		}
		
	}
	
}